package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.annotation.WebUsed;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.OrderLogistics;
import com.xinhe.web.request.OrderByShopCartModel;
import com.xinhe.web.request.OrderModel;
import com.xinhe.web.request.OrderSendModel;
import com.xinhe.web.response.OrderBuyerView;
import com.xinhe.web.response.OrderDetailView;
import com.xinhe.web.response.OrderView;
import com.xinhe.web.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Set;

@Api(value = "商品订单", tags = {"商品订单"})
@RestController
@RequestMapping(value = {"/order"}, produces = {"application/json;charset=UTF-8"})

public class OrderController {
    @Autowired
    private OrderService orderService;

    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "分页查询商品订单")
    @RequestMapping({"/pageOrder"})
    public QueryResults<OrderView> pageOrder(Long userId, String orderType, String orderStatus,
                                             String code, int pageNum, int pageSize) {
        return this.orderService.pageOrder(userId,  orderType,  orderStatus,
                 code,  pageNum,  pageSize);
    }
    @WebUsed
    @ApiOperation(httpMethod = "GET", value = "商品订单详情（会员用户）")
    @ApiImplicitParam(name = "orderId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailOrder"})
    public Result<OrderDetailView> detailOrder(Long orderId) {//会员id
        return this.orderService.detailOrder(orderId);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询商品订单（商家）")
    @RequestMapping({"/pageOrderBySeller"})
    public QueryResults<OrderView> pageOrderBySeller(Long sellerUserId, int pageNum, int pageSize) {//商家会员id
        return this.orderService.pageOrderBySeller(sellerUserId, pageNum, pageSize);
    }
    @ApiOperation(httpMethod = "POST", value = "保存商品订单")
    @RequestMapping({"/saveOrder"})
    public Result saveOrder(@Valid OrderModel model) {
        return this.orderService.saveModel(model);
    }

    @ApiOperation(httpMethod = "POST", value = "提交到订单")
    @RequestMapping({"/saveOrderByShopCart"})
    public Result saveOrderByShopCart(@Valid @RequestBody OrderByShopCartModel model) {
        return this.orderService.saveOrderByShopCart(model);
    }

    @ApiOperation(httpMethod = "POST", value = "买家订单列表(userId查当前用户)")
    @RequestMapping({"/pageByBuyerOrder"})
    QueryResults<OrderBuyerView> pageByBuyerOrder(Long userId, String status, Set<String> types, int pageNum, int pageSize) {
        return this.orderService.pageOrderByBuyer(userId,  status,types,  pageNum,  pageSize);
    }

    @ApiOperation(httpMethod = "POST", value = "买家提醒发货")
    @RequestMapping({"/saveRemindSend"})
    public Result saveRemindSend(Long orderId) {
        return this.orderService.saveRemindSend(orderId);
    }

    @ApiOperation(httpMethod = "POST", value = "取消订单")
    @RequestMapping({"/cancelOrder"})
    public Result cancelOrder(Long orderId) {
        return this.orderService.cancelOrder(orderId);
    }

    @ApiOperation(httpMethod = "POST", value = "订单发货")
    @RequestMapping({"/sendOrder"})
    public Result sendOrder(@Valid OrderSendModel model, BindingResult bind) {
        return this.orderService.sendOrder(model);
    }

    @ApiOperation(httpMethod = "POST", value = "查看物流")
    @RequestMapping({"/seeLogistics"})
    public Result seeLogistics(Long orderId) {
        return this.orderService.seeLogistics(orderId);
    }

    @ApiOperation(httpMethod = "POST", value = "订单签收")
    @RequestMapping({"/receiveOrder"})
    public Result receiveOrder(Long orderId) {
        return this.orderService.receiveOrder(orderId);
    }

    @ApiOperation(httpMethod = "GET", value = "删除商品订单")
    @ApiImplicitParam(name = "orderId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteOrder"})
    public Result deleteOrder(Long orderId) {
        return this.orderService.delete(orderId);
    }


    @ApiOperation(httpMethod = "GET", value = "自提点扫码调用接口 商品订单详情")
    @ApiImplicitParam(name = "orderId", value = "标识", required = true)
    @RequestMapping({"/detailOrderByShop"})
    public Result<OrderDetailView> detailOrderByShop(Long orderId) {
        return this.orderService.detailOrderByShop(orderId);
    }
}
